<html><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <title>客户资料</title>
	<#assign base=request.contextPath  />
	<base id="basePath" href="${base}">

	<base id="basePath" href="${base}">
	<link rel="stylesheet" href="${base}/css/demo.css" type="text/css">
	<link rel="stylesheet" href="${base}/css/zTreeStyle.css" type="text/css">
	<script type="text/javascript" src="${base}/js/ztree/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="${base}/js/ztree/jquery.ztree.core.js"></script>
	<script type="text/javascript" src="${base}/js/zhang.js"></script>
	<script type="text/javascript" src="${base}/js/ztree/jquery.ztree.excheck.js"></script>
	<script type="text/javascript" src="${base}/js/ztree/jquery.ztree.exedit.js"></script>



  <link rel="stylesheet" href="${base}/js/layui/css/layui.css?t=1534970980648" media="all">
  <style>
	form{
  		padding: 20px;
  	}
  	.layui-btn-radius{
     			border-radius: 5px;
     		}

  </style>
</head>
	<body>
		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
	  <legend>客户资料</legend>
	</fieldset>

	<div class="demoTable"style="padding:15px;">
         <button class="layui-btn layui-btn-radius" id="btn2" data-method="offset" type="button" style="background-color: #0092EF;">添加客户资料</button>
        <div class="layui-inline layui-form" style="float:right;">
        <div class="layui-input-inline">
            <select name="interest"  id="sech"  lay-search="">
                <option value="">请选择要搜索的列</option>
                <option value="name">姓名</option>
                <option value="phone">手机号</option>
                <option value="address">家庭住址</option>
                <option value="competitor">竞争对手</option>
                <option value="budget">预算</option>
                <option value="construction_card">建卡</option>
                <option value="lev">等级</option>
                <option value="source">来源</option>
                <option value="visit">是否参观</option>
                <option value="salesperson">销售员</option>
                <option value="weixin">微信号</option>
                <option value="visitNumber">参观次数</option>
                <option value="followUp">跟进次数</option>
                <option value="input_person">录入人</option>
                <option value="objection">客户异议</option>
            </select>
        </div>

    	  <div class="layui-inline">
              	    <input class="layui-input" name="id" id="demoReload" autocomplete="off">
              	  </div>
    	  <button class="layui-btn layui-btn-radius" id="btn1" data-type="reload" style="background-color: #0092EF;">搜索</button>
       </div>
    </div>
<table class="layui-hide" id="test" lay-filter="user"></table>

<script type="text/html" id="barDemo">
  <i class="layui-icon layui-icon-edit" lay-event="edit" id="updatebaby" style="font-size: 20px;"></i>&nbsp;&nbsp;&nbsp;
  <i class="layui-icon layui-icon-delete layui-btn-xs" lay-event="del" id="delectbaby" href="javascript:void(0)"  onclick="onDelete('{{d.customerId}}')"  style="font-size: 20px;" ></i>
</script>
<script src="${base}/js/jquery.min.js"></script>
<script type="text/javascript" src="${base}/js/ztree/jquery-1.4.4.min.js"></script>
<script src="${base}/js/layui/layui.js"></script>
<script>

layui.use(['form', 'layedit', 'laydate','table'], function(){
  var form = layui.form
  ,$ = layui.jquery
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate
  table = layui.table;

  table.render({
    elem: '#test'
    ,url:'${base}/customer/selectCustomer'//数据接口
    ,toolbar: '#toolbarDemo'
        ,defaultToolbar: ['filter', 'print', 'exports']
    ,cols: [[
     {field:'customerId', title: 'ID',templet:function(val){
                                                return val.LAY_INDEX
                                                },width:60, field: true,align:'center'}
      ,{field:'name', width:80, title: '姓名',align:'center'}
      ,{field:'phone', width:120, title: '联系电话',align:'center'}
          ,{field:'expected',width:120,templet:function(val){
                  return DateFormat(val.expected);
              }, title: '大概预产期',align:'center'}

      ,{field:'address',width:130, title: '家庭住址',align:'center'}
          ,{field:'budget',width:80, title: '预算',align:'center'}
          ,{field:'source',width:120, title: '来源',align:'center'}
          ,{field:'competitor', width:100, title: '竞争对手',align:'center'}
          ,{field:'lev',width:90, title: '客户等级',align:'center'}
      ,{field:'salesperson',width:80, title: '销售员',align:'center'}
      ,{field:'weixin',width:100, title: '微信号',align:'center'}
       ,{field:'visit',width:90, title: '是否参观',align:'center'}
      ,{field:'visitNumber',width:130, title: '参观次数',align:'center'}
      ,{field:'followUp',width:130, title: '跟进次数',align:'center'}
      ,{field:'constructionCard', width:120, title: '建卡地',align:'center'}
      ,{field:'objection',width:130,align:'center', title: '客户异议',align:'center'}
      ,{field:'inputPerson',width:80, title: '录入人',align:'center'}
      ,{field:'remarks',width:130, title: '备注',align:'center'}
      ,{field: 'right', title:'操作', toolbar: '#barDemo', width:130, align: 'center'}
    ]]
    ,id:'testReload'
    ,height:500
    ,page: {
       layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
       ,theme: '#0092EF'
       ,limit:20
    }
    ,done: function(res, curr, count){
        this.where={};
    }
  });

    var active = {
      	offset: function(othis){
      	  var type = othis.data('type')
      	  ,text = othis.text();
  		  layer.open({
  		  type: 2,
  		  title: '添加客户',
  		  shade:0,
  		  offset: 'auto',
  		  shade: 0.2,
  		  shadeClose:false ,
  		  offset: 't',
          area:['720px','100%'],
  		  content: '${base}/customer/client_add'
  		});
  	}
    };
  $('#btn2').on('click', function(){
      var othis = $(this), method = othis.data('method');
      active[method] ? active[method].call(this, othis) : '';
    });










      //编辑弹出层
          table.on('tool(user)', function(obj){
            var layEvent = obj.event;
            if(layEvent=="edit"){
                       var data = obj.data;
                        //示范一个公告层
                        layer.open({
                            type: 2,
                            title: '编辑客户信息',
                            shadeClose:false ,
                            offset: 't',
                                      area:['720px','100%'],
                            content: '${base}/customer/client_edit',
                            success: function (layero, index) {
                                //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                                var iframeWin = window[layero.find('iframe')[0]['name']];
                                iframeWin.$("#name").val(data.name);
                                iframeWin.$("#phone").val(data.phone);
                                iframeWin.$("#date").val(DateFormat(data.expected));
                                iframeWin.$("#address").val(data.address);
                                iframeWin.$("#competitor").val(data.competitor);
                                iframeWin.$("#budget").val(data.budget);
                                iframeWin.$("#constructionCard").val(data.constructionCard);
                                iframeWin.$("#lev").val(data.lev);
                                iframeWin.$("#inputPerson").val(data.inputPerson);
                                iframeWin.$("#objection").val(data.objection);
                                iframeWin.$("#source").val(data.source);
                                iframeWin.$("#visit").val(data.visit);
                                iframeWin.$("#salesperson").val(data.salesperson);
                                iframeWin.$("#weixin").val(data.weixin);
                                iframeWin.$("#visitNumber").val(data.visitNumber);
                                iframeWin.$("#followUp").val(data.followUp);
                                iframeWin.$("#remarks").val(data.remarks);
                                iframeWin.$("#customerId").val(data.customerId);
                                //渲染一下form表单
                                iframeWin.layui.form.render('select');
                                iframeWin.layui.form.render();
                            }
                        });
            }

      });
//清空搜索框
layui.form.on('select()', function(data){
 $("#demoReload").val("")
});
//实现搜索
$('#btn1').on('click', function(){
   var sechLin=$("#sech").val();
   var sechData=$("#demoReload").val();

      var whereData={};
      whereData.lin=sechLin;
      whereData.data=Trim(sechData);
      whereData.page=1;
      whereData.limit=10;

              var table = layui.table;
              //表刷新方法
              table.reload('testReload', {
                  url:'${base}/customer/selectCustomer'
                  ,where: whereData //设定异步数据接口的额外参数
              });
  });
    String.prototype.trim = function() {
      return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    }



});




//删除
function onDelete(customerId){
//提示是否删除这条数据
//data里边的customerId是需要和实体类里边的id是一样的,不然是传不过来参数的
layer.confirm('真的要删除吗?',function(index){
    $.ajax({
        type:"POST",
        url:"${base}/customer/deleteCustomer",
        data:{"customerId":customerId},
        sync:false,
        success:function(data){
            //alert("删除成功")
            var table = layui.table;
            //表刷新方法
             table.reload('testReload', {
             url:'${base}/customer/selectCustomer'
             ,where: {} //设定异步数据接口的额外参数
          });
            //关闭删除是否删除的提示框
              layer.close(index);
        }
    });
    });
}

//键盘事件
   $("body").bind("keydown",function(e){
       // 兼容FF和IE和Opera
       var theEvent = e || window.event;
       var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
       if (code == 13) {
           //回车执行查询
           $("#btn1").click();
       }
   });



</script>
</body>
</html>